(function($) {
	$.fn.truncateText = function(options) {
    	var defaults = {
        	length: 10,
            ellipsisText: "...", // can be string ot html element, change contentType accordingly
			contentType: 'text' // text or html
		};
        var options = $.extend(defaults, options);
        return this.each(function() {
        	var me = $(this);

			if( options.contentType == "text" ) {
				var textContent = me.text();
			} else if( options.contentType == "html" ) {
				var textContent = me.html();
			}

            if(textContent.length > options.length) {
				var splitPosition = textContent.indexOf(' ', options.length);
				if(splitPosition != "-1") {
					var truncatedText = textContent.substring(0, splitPosition);
					if( options.contentType == "text" ) {
						truncatedText += options.ellipsisText;
						me.text(truncatedText);
						me.attr({title : textContent});
					} else if( options.contentType == "html" ) {
						me.html(truncatedText);
						me.append(options.ellipsisText);
					}
				}
			}
		});
	}
})(jQuery);